% 有两个参考系，S1和S2，S2相对于S1以速度b向右运动
% S1中观察到的Lorentz实标量场为 u = sin(wt-kx)
% 演示在S2中的观察
% 可能有 bug
% Gitee Repo

clc
clear

L = 2;
dx = 0.01;
_x_grid = -L:dx:L;

b = 0.1;
g = 1/sqrt(1-b^2);

Lorentz = [g,g*b,0,0;g*b,g,0,0;0,0,1,0;0,0,0,1];

v = 0.2; % S1下的波速
T = 5; % S1下的周期

w = 2*pi/T;
k = w/v;

figure
hold on
axis equal

for tick = 0:100
    _t = 0.1*tick;

    _x = [_t*ones(size(_x_grid));_x_grid;0*_x_grid;0*_x_grid];
    x = Lorentz*_x;

    u_rel = sin(w*x(1,:)-k*x(2,:));
    u_classical = sin((w-k*b)*_x(1,:)-k*_x(2,:));

    clf
    hold on
    plot(_x_grid,u_rel);
    plot(_x_grid,u_classical,'--');

    xlabel('x')
    ylabel('u')
    legend('relativity','classical')

    drawnow;
    pause(0.1);
end

